package com.fxm.controller;

import com.fxm.client.QuestionClient;
import com.fxm.returns.RespEntity;
import com.fxm.returns.RespTable;
import com.fxm.vo.param.QuestionParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 题目管理 前端控制器
 * </p>
 *
 * @author fxm
 * @since 2021-02-20
 */
@RestController
@RequestMapping("/question")
@Slf4j
@Api(value = "题目管理", tags = "题目管理")
public class QuestionController {

    @Autowired
    private QuestionClient questionClient;

    @GetMapping("/list")
    @ApiOperation(value = "题目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true)
    })
    public RespTable questionList(@RequestParam(value = "page", required = true) Integer page,
                                  @RequestParam(value = "limit", required = true) Integer limit) {
        RespTable respTable = questionClient.questionList(page, limit);
        return respTable;
    }

    @GetMapping("/search")
    @ApiOperation(value = "搜索题目")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "questionTitle", value = "题目名称", required = false)
    })
    public RespTable questionSearch(@RequestParam(value = "page", required = true) Integer page,
                                    @RequestParam(value = "limit", required = true) Integer limit,
                                    @RequestParam(value = "questionTitle", required = false) String questionTitle) {
        RespTable respTable = questionClient.searchQuestion(page, limit, questionTitle);
        return respTable;
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加题目")
    public RespEntity insertQuestion(QuestionParam questionParam) {
        RespEntity respEntity = questionClient.insertQuestion(questionParam);
        return respEntity;
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑题目")
    public RespEntity updateQuestion(QuestionParam questionParam) {
        RespEntity respEntity = questionClient.updateQuestion(questionParam);
        return respEntity;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除题目")
    public RespEntity deleteQuestion(@RequestParam(value = "id", required = true) Integer id) {
        RespEntity respEntity = questionClient.deleteQuestion(id);
        return respEntity;
    }

    @DeleteMapping("/batchDelete")
    @ApiOperation(value = "批量删除题目")
    public RespEntity batchDeleteQuestion(@RequestParam(value = "ids", required = true) Integer[] ids) {
        RespEntity respEntity = questionClient.batchDeleteQuestion(ids);
        return respEntity;
    }



}
